package com.example.home.logistics.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.logistics.bean.LogisticsSearchDetaiBean;

import java.util.List;

public class LogisticsSearchDetaiAdapter extends RecyclerView.Adapter<LogisticsSearchDetaiAdapter.MyHoldy> {
    private Context context;
    private List<LogisticsSearchDetaiBean.DataBean.StepListBean> list;

    public LogisticsSearchDetaiAdapter(Context context, List<LogisticsSearchDetaiBean.DataBean.StepListBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_logisic, parent, false);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        holder.eventAt.setText(list.get(position).getEventAt());
        holder.addressAt.setText(list.get(position).getAddressAt());
        holder.stateName.setText(list.get(position).getStateName());
        if (position == 0) {
            holder.xian.setVisibility(View.GONE);
        } else {
            holder.xian.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private TextView eventAt;
        private TextView addressAt;
        private TextView stateName;
        private ImageView xian;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            eventAt = itemView.findViewById(R.id.eventAt);
            addressAt = itemView.findViewById(R.id.addressAt);
            stateName = itemView.findViewById(R.id.stateName);
            xian = itemView.findViewById(R.id.xian);
        }
    }
}
